﻿/*
 *	Copyright (c) 2009 Queensland University of Technology. All rights reserved.
 *	The QUT Bioinformatics Collection is open source software released under the 
 *	Microsoft Public License (Ms-PL): http://www.microsoft.com/opensource/licenses.mspx.
 */
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

namespace QUT.Bio.Util {
	public partial class BorderLayout : UserControl {
		public BorderLayout() {
			InitializeComponent();
		}

		private FrameworkElement north;
		private FrameworkElement south;
		private FrameworkElement east;
		private FrameworkElement west;
		private FrameworkElement centre;
		
		public FrameworkElement North {
			get {
				return north;
			}
			set {
				if ( north != null ) {
					root.Children.Remove( north );
				}
				
				north = value;
				AddElement( north, 0, 0, 1, 3 );
			}
		}

		public FrameworkElement South {
			get {
				return south;
			}
			set {
				if ( south != null ) {
					root.Children.Remove( south );
				}

				south = value;
				AddElement( south, 2, 0, 1, 3 );
			}
		}

		public FrameworkElement East {
			get {
				return east;
			}
			set {
				if ( east != null ) {
					root.Children.Remove( east );
				}

				east = value;
				AddElement( east, 1, 2, 1, 1 );
			}
		}

		public FrameworkElement West {
			get {
				return west;
			}
			set {
				if ( west != null ) {
					root.Children.Remove( west );
				}

				west = value;
				AddElement( west, 1, 0, 1, 1 );
			}
		}

		public FrameworkElement Centre {
			get {
				return centre;
			}
			set {
				if ( centre != null ) {
					root.Children.Remove( centre );
				}

				centre = value;
				AddElement( centre, 1, 1, 1, 1 );
			}
		}
		
		void AddElement( 
			FrameworkElement element, 
			int row, 
			int col, 
			int rowSpan, 
			int colSpan 
		) {
			root.Children.Add( element );
			element.SetValue( Grid.RowProperty, row );
			element.SetValue( Grid.ColumnProperty, col );
			element.SetValue( Grid.ColumnSpanProperty, colSpan );
			element.SetValue( Grid.RowSpanProperty, rowSpan );
		}
	}
}
